import android.net.Uri;
import android.provider.Settings.ResetMode;
import android.util.ArrayMap;
+import android.util.Log;
import android.util.Pair;
import com.android.internal.annotations.GuardedBy;
new ArrayMap<>();
@GuardedBy("sLock")
private static Map<String, Pair<ContentObserver, Integer>> sNamespaces = new HashMap<>();
+ private static final String TAG = "DeviceConfig";
// Should never be invoked
private DeviceConfig() {
@RequiresPermission(READ_DEVICE_CONFIG)
public static int getInt(String namespace, String name, int defaultValue) {
String value = getProperty(namespace, name);
+ if (value == null) {
+ return defaultValue;
+ }
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
+ Log.e(TAG, "Parsing integer failed for " + namespace + ":" + name);
return defaultValue;
}
}
@RequiresPermission(READ_DEVICE_CONFIG)
public static long getLong(String namespace, String name, long defaultValue) {
String value = getProperty(namespace, name);
+ if (value == null) {
+ return defaultValue;
+ }
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
+ Log.e(TAG, "Parsing long failed for " + namespace + ":" + name);
return defaultValue;
}
}
@RequiresPermission(READ_DEVICE_CONFIG)
public static float getFloat(String namespace, String name, float defaultValue) {
String value = getProperty(namespace, name);
+ if (value == null) {
+ return defaultValue;
+ }
try {
return Float.parseFloat(value);
} catch (NumberFormatException e) {
- return defaultValue;
- } catch (NullPointerException e) {
+ Log.e(TAG, "Parsing float failed for " + namespace + ":" + name);
return defaultValue;
}
}
public int getInt(@NonNull String name, int defaultValue) {
Preconditions.checkNotNull(name);
String value = mMap.get(name);
+ if (value == null) {
+ return defaultValue;
+ }
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
+ Log.e(TAG, "Parsing int failed for " + name);
return defaultValue;
}
}
public long getLong(@NonNull String name, long defaultValue) {
Preconditions.checkNotNull(name);
String value = mMap.get(name);
+ if (value == null) {
+ return defaultValue;
+ }
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
+ Log.e(TAG, "Parsing long failed for " + name);
return defaultValue;
}
}
public float getFloat(@NonNull String name, float defaultValue) {
Preconditions.checkNotNull(name);
String value = mMap.get(name);
+ if (value == null) {
+ return defaultValue;
+ }
try {
return Float.parseFloat(value);
} catch (NumberFormatException e) {
- return defaultValue;
- } catch (NullPointerException e) {
+ Log.e(TAG, "Parsing float failed for " + name);
return defaultValue;
}
}