FileDocCategorySizeDatePackage
SystemProperties.javaAPI DocAndroid 5.1 API5742Thu Mar 12 22:22:10 GMT 2015android.os

SystemProperties

public class SystemProperties extends Object
Gives access to the system properties store. The system properties store contains a list of string key-value pairs. {@hide}

Fields Summary
public static final int
PROP_NAME_MAX
public static final int
PROP_VALUE_MAX
private static final ArrayList
sChangeCallbacks
Constructors Summary
Methods Summary
public static voidaddChangeCallback(java.lang.Runnable callback)

        synchronized (sChangeCallbacks) {
            if (sChangeCallbacks.size() == 0) {
                native_add_change_callback();
            }
            sChangeCallbacks.add(callback);
        }
    
static voidcallChangeCallbacks()

        synchronized (sChangeCallbacks) {
            //Log.i("foo", "Calling " + sChangeCallbacks.size() + " change callbacks!");
            if (sChangeCallbacks.size() == 0) {
                return;
            }
            ArrayList<Runnable> callbacks = new ArrayList<Runnable>(sChangeCallbacks);
            for (int i=0; i<callbacks.size(); i++) {
                callbacks.get(i).run();
            }
        }
    
public static java.lang.Stringget(java.lang.String key)
Get the value for the given key.

return
an empty string if the key isn't found
throws
IllegalArgumentException if the key exceeds 32 characters


         
           
           
           
           
           
        

                                 
         
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get(key);
    
public static java.lang.Stringget(java.lang.String key, java.lang.String def)
Get the value for the given key.

return
if the key isn't found, return def if it isn't null, or an empty string otherwise
throws
IllegalArgumentException if the key exceeds 32 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get(key, def);
    
public static booleangetBoolean(java.lang.String key, boolean def)
Get the value for the given key, returned as a boolean. Values 'n', 'no', '0', 'false' or 'off' are considered false. Values 'y', 'yes', '1', 'true' or 'on' are considered true. (case sensitive). If the key does not exist, or has any other value, then the default result is returned.

param
key the key to lookup
param
def a default value to return
return
the key parsed as a boolean, or def if the key isn't found or is not able to be parsed as a boolean.
throws
IllegalArgumentException if the key exceeds 32 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get_boolean(key, def);
    
public static intgetInt(java.lang.String key, int def)
Get the value for the given key, and return as an integer.

param
key the key to lookup
param
def a default value to return
return
the key parsed as an integer, or def if the key isn't found or cannot be parsed
throws
IllegalArgumentException if the key exceeds 32 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get_int(key, def);
    
public static longgetLong(java.lang.String key, long def)
Get the value for the given key, and return as a long.

param
key the key to lookup
param
def a default value to return
return
the key parsed as a long, or def if the key isn't found or cannot be parsed
throws
IllegalArgumentException if the key exceeds 32 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        return native_get_long(key, def);
    
private static native voidnative_add_change_callback()

private static native java.lang.Stringnative_get(java.lang.String key)

private static native java.lang.Stringnative_get(java.lang.String key, java.lang.String def)

private static native booleannative_get_boolean(java.lang.String key, boolean def)

private static native intnative_get_int(java.lang.String key, int def)

private static native longnative_get_long(java.lang.String key, long def)

private static native voidnative_set(java.lang.String key, java.lang.String def)

public static voidset(java.lang.String key, java.lang.String val)
Set the value for the given key.

throws
IllegalArgumentException if the key exceeds 32 characters
throws
IllegalArgumentException if the value exceeds 92 characters

        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (val != null && val.length() > PROP_VALUE_MAX) {
            throw new IllegalArgumentException("val.length > " +
                PROP_VALUE_MAX);
        }
        native_set(key, val);