Add way to migrate CM specific settings to CMSettingsProvider
issue-id: CYNGNOS-829 Change-Id: I08743ebf9ffd3846ae501ed41e396b1556dc41cf
This commit is contained in:
committed by
Gerrit Code Review
parent
8fc6affd38
commit
05d0129478
@@ -20,6 +20,7 @@ import android.content.ContentResolver;
|
||||
import android.content.IContentProvider;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
@@ -44,10 +45,57 @@ public final class CMSettings {
|
||||
}
|
||||
}
|
||||
|
||||
// region Call Methods
|
||||
|
||||
/**
|
||||
* @hide - User handle argument extra to the fast-path call()-based requests
|
||||
*/
|
||||
public static final String CALL_METHOD_USER_KEY = "_user";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method on SettingsProvider to read from 'system' table.
|
||||
*/
|
||||
public static final String CALL_METHOD_GET_SYSTEM = "GET_system";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method on SettingsProvider to read from 'secure' table.
|
||||
*/
|
||||
public static final String CALL_METHOD_GET_SECURE = "GET_secure";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method on SettingsProvider to read from 'global' table.
|
||||
*/
|
||||
public static final String CALL_METHOD_GET_GLOBAL = "GET_global";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method to write to 'system' table
|
||||
*/
|
||||
public static final String CALL_METHOD_PUT_SYSTEM = "PUT_system";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method to write to 'secure' table
|
||||
*/
|
||||
public static final String CALL_METHOD_PUT_SECURE = "PUT_secure";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method to write to 'global' table
|
||||
*/
|
||||
public static final String CALL_METHOD_PUT_GLOBAL= "PUT_global";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method on CMSettingsProvider to migrate CM settings
|
||||
*/
|
||||
public static final String CALL_METHOD_MIGRATE_SETTINGS = "migrate_settings";
|
||||
|
||||
/**
|
||||
* @hide - Private call() method on CMSettingsProvider to migrate CM settings for a user
|
||||
*/
|
||||
public static final String CALL_METHOD_MIGRATE_SETTINGS_FOR_USER = "migrate_settings_for_user";
|
||||
|
||||
// endregion
|
||||
|
||||
// Thread-safe.
|
||||
private static class NameValueCache {
|
||||
// TODO Add call options for fast path at insert and get
|
||||
|
||||
private final String mVersionSystemProperty;
|
||||
private final Uri mUri;
|
||||
|
||||
@@ -62,9 +110,17 @@ public final class CMSettings {
|
||||
// Initially null; set lazily and held forever. Synchronized on 'this'.
|
||||
private IContentProvider mContentProvider = null;
|
||||
|
||||
public NameValueCache(String versionSystemProperty, Uri uri) {
|
||||
// The method we'll call (or null, to not use) on the provider
|
||||
// for the fast path of retrieving settings.
|
||||
private final String mCallGetCommand;
|
||||
private final String mCallSetCommand;
|
||||
|
||||
public NameValueCache(String versionSystemProperty, Uri uri,
|
||||
String getCommand, String setCommand) {
|
||||
mVersionSystemProperty = versionSystemProperty;
|
||||
mUri = uri;
|
||||
mCallGetCommand = getCommand;
|
||||
mCallSetCommand = setCommand;
|
||||
}
|
||||
|
||||
private IContentProvider lazyGetProvider(ContentResolver cr) {
|
||||
@@ -79,7 +135,30 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a a string value with the specified name from the name/value cache if possible. If
|
||||
* Puts a string name/value pair into the content provider for the specified user.
|
||||
* @param cr The content resolver to use.
|
||||
* @param name The name of the key to put into the content provider.
|
||||
* @param value The value to put into the content provider.
|
||||
* @param userId The user id to use for the content provider.
|
||||
* @return Whether the put was successful.
|
||||
*/
|
||||
public boolean putStringForUser(ContentResolver cr, String name, String value,
|
||||
final int userId) {
|
||||
try {
|
||||
Bundle arg = new Bundle();
|
||||
arg.putString(Settings.NameValueTable.VALUE, value);
|
||||
arg.putInt(CALL_METHOD_USER_KEY, userId);
|
||||
IContentProvider cp = lazyGetProvider(cr);
|
||||
cp.call(cr.getPackageName(), mCallSetCommand, name, arg);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "Can't set key " + name + " in " + mUri, e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string value with the specified name from the name/value cache if possible. If
|
||||
* not, it will use the content resolver and perform a query.
|
||||
* @param cr Content resolver to use if name/value cache does not contain the name or if
|
||||
* the cache version is older than the current version.
|
||||
@@ -90,6 +169,7 @@ public final class CMSettings {
|
||||
public String getStringForUser(ContentResolver cr, String name, final int userId) {
|
||||
final boolean isSelf = (userId == UserHandle.myUserId());
|
||||
if (isSelf) {
|
||||
if (LOCAL_LOGV) Log.d(TAG, "get setting for self");
|
||||
long newValuesVersion = SystemProperties.getLong(mVersionSystemProperty, 0);
|
||||
|
||||
// Our own user's settings data uses a client-side cache
|
||||
@@ -115,6 +195,40 @@ public final class CMSettings {
|
||||
|
||||
IContentProvider cp = lazyGetProvider(cr);
|
||||
|
||||
// Try the fast path first, not using query(). If this
|
||||
// fails (alternate Settings provider that doesn't support
|
||||
// this interface?) then we fall back to the query/table
|
||||
// interface.
|
||||
if (mCallGetCommand != null) {
|
||||
try {
|
||||
Bundle args = null;
|
||||
if (!isSelf) {
|
||||
args = new Bundle();
|
||||
args.putInt(CALL_METHOD_USER_KEY, userId);
|
||||
}
|
||||
Bundle b = cp.call(cr.getPackageName(), mCallGetCommand, name, args);
|
||||
if (b != null) {
|
||||
String value = b.getPairValue();
|
||||
// Don't update our cache for reads of other users' data
|
||||
if (isSelf) {
|
||||
synchronized (this) {
|
||||
mValues.put(name, value);
|
||||
}
|
||||
} else {
|
||||
if (LOCAL_LOGV) Log.i(TAG, "call-query of user " + userId
|
||||
+ " by " + UserHandle.myUserId()
|
||||
+ " so not updating cache");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
// If the response Bundle is null, we fall through
|
||||
// to the query interface below.
|
||||
} catch (RemoteException e) {
|
||||
// Not supported by the remote side? Fall through
|
||||
// to query().
|
||||
}
|
||||
}
|
||||
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = cp.query(cr.getPackageName(), mUri, SELECT_VALUE, NAME_EQ_PLACEHOLDER,
|
||||
@@ -143,9 +257,8 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* System settings, containing miscellaneous CM system preferences. This
|
||||
* table holds simple name/value pairs. There are convenience
|
||||
* functions for accessing individual settings entries.
|
||||
* System settings, containing miscellaneous CM system preferences. This table holds simple
|
||||
* name/value pairs. There are convenience functions for accessing individual settings entries.
|
||||
*/
|
||||
public static final class System extends Settings.NameValueTable {
|
||||
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/system");
|
||||
@@ -154,10 +267,22 @@ public final class CMSettings {
|
||||
|
||||
private static final NameValueCache sNameValueCache = new NameValueCache(
|
||||
SYS_PROP_CM_SETTING_VERSION,
|
||||
CONTENT_URI);
|
||||
CONTENT_URI,
|
||||
CALL_METHOD_GET_SYSTEM,
|
||||
CALL_METHOD_PUT_SYSTEM);
|
||||
|
||||
// region Methods
|
||||
|
||||
/**
|
||||
* Construct the content URI for a particular name/value pair, useful for monitoring changes
|
||||
* with a ContentObserver.
|
||||
* @param name to look up in the table
|
||||
* @return the corresponding content URI
|
||||
*/
|
||||
public static Uri getUriFor(String name) {
|
||||
return Settings.NameValueTable.getUriFor(CONTENT_URI, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a name in the database.
|
||||
* @param resolver to access the database with
|
||||
@@ -170,8 +295,8 @@ public final class CMSettings {
|
||||
|
||||
/** @hide */
|
||||
public static String getStringForUser(ContentResolver resolver, String name,
|
||||
int userHandle) {
|
||||
return sNameValueCache.getStringForUser(resolver, name, userHandle);
|
||||
int userId) {
|
||||
return sNameValueCache.getStringForUser(resolver, name, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,11 +307,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putString(ContentResolver resolver, String name, String value) {
|
||||
return putString(resolver, CONTENT_URI, name, value);
|
||||
return putStringForUser(resolver, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putStringForUser(ContentResolver resolver, String name, String value,
|
||||
int userId) {
|
||||
return sNameValueCache.putStringForUser(resolver, name, value, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as an integer. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to an integer
|
||||
* for you. The default value will be returned if the setting is
|
||||
@@ -200,7 +331,12 @@ public final class CMSettings {
|
||||
* or not a valid integer.
|
||||
*/
|
||||
public static int getInt(ContentResolver cr, String name, int def) {
|
||||
String v = getString(cr, name);
|
||||
return getIntForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static int getIntForUser(ContentResolver cr, String name, int def, int userId) {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return v != null ? Integer.parseInt(v) : def;
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -209,7 +345,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as an integer. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to an integer
|
||||
* for you.
|
||||
@@ -228,7 +364,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static int getInt(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getString(cr, name);
|
||||
return getIntForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static int getIntForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return Integer.parseInt(v);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -250,11 +392,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putInt(ContentResolver cr, String name, int value) {
|
||||
return putString(cr, name, Integer.toString(value));
|
||||
return putIntForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putIntForUser(ContentResolver cr, String name, int value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Integer.toString(value), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a {@code long}. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a {@code long}
|
||||
* for you. The default value will be returned if the setting is
|
||||
@@ -268,7 +416,13 @@ public final class CMSettings {
|
||||
* or not a valid {@code long}.
|
||||
*/
|
||||
public static long getLong(ContentResolver cr, String name, long def) {
|
||||
String valString = getString(cr, name);
|
||||
return getLongForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static long getLongForUser(ContentResolver cr, String name, long def,
|
||||
int userId) {
|
||||
String valString = getStringForUser(cr, name, userId);
|
||||
long value;
|
||||
try {
|
||||
value = valString != null ? Long.parseLong(valString) : def;
|
||||
@@ -279,7 +433,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a {@code long}. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a {@code long}
|
||||
* for you.
|
||||
@@ -297,7 +451,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static long getLong(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String valString = getString(cr, name);
|
||||
return getLongForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static long getLongForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String valString = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return Long.parseLong(valString);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -306,7 +466,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for updating a secure settings value as a long
|
||||
* Convenience function for updating a single settings value as a long
|
||||
* integer. This will either create a new entry in the table if the
|
||||
* given name does not exist, or modify the value of the existing row
|
||||
* with that name. Note that internally setting values are always
|
||||
@@ -319,11 +479,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putLong(ContentResolver cr, String name, long value) {
|
||||
return putString(cr, name, Long.toString(value));
|
||||
return putLongForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putLongForUser(ContentResolver cr, String name, long value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Long.toString(value), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a floating point number. Note that internally setting values are
|
||||
* always stored as strings; this function converts the string to an
|
||||
* float for you. The default value will be returned if the setting
|
||||
@@ -337,7 +503,13 @@ public final class CMSettings {
|
||||
* or not a valid float.
|
||||
*/
|
||||
public static float getFloat(ContentResolver cr, String name, float def) {
|
||||
String v = getString(cr, name);
|
||||
return getFloatForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static float getFloatForUser(ContentResolver cr, String name, float def,
|
||||
int userId) {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return v != null ? Float.parseFloat(v) : def;
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -346,7 +518,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single system settings value
|
||||
* as a float. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a float
|
||||
* for you.
|
||||
@@ -365,7 +537,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static float getFloat(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getString(cr, name);
|
||||
return getFloatForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static float getFloatForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
if (v == null) {
|
||||
throw new CMSettingNotFoundException(name);
|
||||
}
|
||||
@@ -390,7 +568,13 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putFloat(ContentResolver cr, String name, float value) {
|
||||
return putString(cr, name, Float.toString(value));
|
||||
return putFloatForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putFloatForUser(ContentResolver cr, String name, float value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Float.toString(value), userId);
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -408,8 +592,8 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Secure settings, containing miscellaneous CM secure preferences. This
|
||||
* table holds simple name/value pairs. There are convenience
|
||||
* Secure settings, containing miscellaneous CM secure preferences. This
|
||||
* table holds simple name/value pairs. There are convenience
|
||||
* functions for accessing individual settings entries.
|
||||
*/
|
||||
public static final class Secure extends Settings.NameValueTable {
|
||||
@@ -419,7 +603,21 @@ public final class CMSettings {
|
||||
|
||||
private static final NameValueCache sNameValueCache = new NameValueCache(
|
||||
SYS_PROP_CM_SETTING_VERSION,
|
||||
CONTENT_URI);
|
||||
CONTENT_URI,
|
||||
CALL_METHOD_GET_SECURE,
|
||||
CALL_METHOD_PUT_SECURE);
|
||||
|
||||
// region Methods
|
||||
|
||||
/**
|
||||
* Construct the content URI for a particular name/value pair, useful for monitoring changes
|
||||
* with a ContentObserver.
|
||||
* @param name to look up in the table
|
||||
* @return the corresponding content URI
|
||||
*/
|
||||
public static Uri getUriFor(String name) {
|
||||
return Settings.NameValueTable.getUriFor(CONTENT_URI, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a name in the database.
|
||||
@@ -433,8 +631,8 @@ public final class CMSettings {
|
||||
|
||||
/** @hide */
|
||||
public static String getStringForUser(ContentResolver resolver, String name,
|
||||
int userHandle) {
|
||||
return sNameValueCache.getStringForUser(resolver, name, userHandle);
|
||||
int userId) {
|
||||
return sNameValueCache.getStringForUser(resolver, name, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,11 +643,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putString(ContentResolver resolver, String name, String value) {
|
||||
return putString(resolver, CONTENT_URI, name, value);
|
||||
return putStringForUser(resolver, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putStringForUser(ContentResolver resolver, String name, String value,
|
||||
int userId) {
|
||||
return sNameValueCache.putStringForUser(resolver, name, value, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as an integer. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to an integer
|
||||
* for you. The default value will be returned if the setting is
|
||||
@@ -463,7 +667,12 @@ public final class CMSettings {
|
||||
* or not a valid integer.
|
||||
*/
|
||||
public static int getInt(ContentResolver cr, String name, int def) {
|
||||
String v = getString(cr, name);
|
||||
return getIntForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static int getIntForUser(ContentResolver cr, String name, int def, int userId) {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return v != null ? Integer.parseInt(v) : def;
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -472,7 +681,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as an integer. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to an integer
|
||||
* for you.
|
||||
@@ -491,7 +700,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static int getInt(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getString(cr, name);
|
||||
return getIntForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static int getIntForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return Integer.parseInt(v);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -513,11 +728,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putInt(ContentResolver cr, String name, int value) {
|
||||
return putString(cr, name, Integer.toString(value));
|
||||
return putIntForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putIntForUser(ContentResolver cr, String name, int value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Integer.toString(value), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a {@code long}. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a {@code long}
|
||||
* for you. The default value will be returned if the setting is
|
||||
@@ -531,7 +752,13 @@ public final class CMSettings {
|
||||
* or not a valid {@code long}.
|
||||
*/
|
||||
public static long getLong(ContentResolver cr, String name, long def) {
|
||||
String valString = getString(cr, name);
|
||||
return getLongForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static long getLongForUser(ContentResolver cr, String name, long def,
|
||||
int userId) {
|
||||
String valString = getStringForUser(cr, name, userId);
|
||||
long value;
|
||||
try {
|
||||
value = valString != null ? Long.parseLong(valString) : def;
|
||||
@@ -542,7 +769,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a {@code long}. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a {@code long}
|
||||
* for you.
|
||||
@@ -560,7 +787,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static long getLong(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String valString = getString(cr, name);
|
||||
return getLongForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static long getLongForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String valString = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return Long.parseLong(valString);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -569,7 +802,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for updating a secure settings value as a long
|
||||
* Convenience function for updating a single settings value as a long
|
||||
* integer. This will either create a new entry in the table if the
|
||||
* given name does not exist, or modify the value of the existing row
|
||||
* with that name. Note that internally setting values are always
|
||||
@@ -582,11 +815,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putLong(ContentResolver cr, String name, long value) {
|
||||
return putString(cr, name, Long.toString(value));
|
||||
return putLongForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putLongForUser(ContentResolver cr, String name, long value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Long.toString(value), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a floating point number. Note that internally setting values are
|
||||
* always stored as strings; this function converts the string to an
|
||||
* float for you. The default value will be returned if the setting
|
||||
@@ -600,7 +839,13 @@ public final class CMSettings {
|
||||
* or not a valid float.
|
||||
*/
|
||||
public static float getFloat(ContentResolver cr, String name, float def) {
|
||||
String v = getString(cr, name);
|
||||
return getFloatForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static float getFloatForUser(ContentResolver cr, String name, float def,
|
||||
int userId) {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return v != null ? Float.parseFloat(v) : def;
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -609,7 +854,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single system settings value
|
||||
* as a float. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a float
|
||||
* for you.
|
||||
@@ -628,7 +873,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static float getFloat(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getString(cr, name);
|
||||
return getFloatForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static float getFloatForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
if (v == null) {
|
||||
throw new CMSettingNotFoundException(name);
|
||||
}
|
||||
@@ -653,7 +904,13 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putFloat(ContentResolver cr, String name, float value) {
|
||||
return putString(cr, name, Float.toString(value));
|
||||
return putFloatForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putFloatForUser(ContentResolver cr, String name, float value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Float.toString(value), userId);
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -770,8 +1027,8 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Global settings, containing miscellaneous CM global preferences. This
|
||||
* table holds simple name/value pairs. There are convenience
|
||||
* Global settings, containing miscellaneous CM global preferences. This
|
||||
* table holds simple name/value pairs. There are convenience
|
||||
* functions for accessing individual settings entries.
|
||||
*/
|
||||
public static final class Global extends Settings.NameValueTable {
|
||||
@@ -781,10 +1038,22 @@ public final class CMSettings {
|
||||
|
||||
private static final NameValueCache sNameValueCache = new NameValueCache(
|
||||
SYS_PROP_CM_SETTING_VERSION,
|
||||
CONTENT_URI);
|
||||
CONTENT_URI,
|
||||
CALL_METHOD_GET_GLOBAL,
|
||||
CALL_METHOD_PUT_GLOBAL);
|
||||
|
||||
// region Methods
|
||||
|
||||
/**
|
||||
* Construct the content URI for a particular name/value pair, useful for monitoring changes
|
||||
* with a ContentObserver.
|
||||
* @param name to look up in the table
|
||||
* @return the corresponding content URI
|
||||
*/
|
||||
public static Uri getUriFor(String name) {
|
||||
return Settings.NameValueTable.getUriFor(CONTENT_URI, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a name in the database.
|
||||
* @param resolver to access the database with
|
||||
@@ -797,8 +1066,8 @@ public final class CMSettings {
|
||||
|
||||
/** @hide */
|
||||
public static String getStringForUser(ContentResolver resolver, String name,
|
||||
int userHandle) {
|
||||
return sNameValueCache.getStringForUser(resolver, name, userHandle);
|
||||
int userId) {
|
||||
return sNameValueCache.getStringForUser(resolver, name, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -809,11 +1078,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putString(ContentResolver resolver, String name, String value) {
|
||||
return putString(resolver, CONTENT_URI, name, value);
|
||||
return putStringForUser(resolver, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putStringForUser(ContentResolver resolver, String name, String value,
|
||||
int userId) {
|
||||
return sNameValueCache.putStringForUser(resolver, name, value, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as an integer. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to an integer
|
||||
* for you. The default value will be returned if the setting is
|
||||
@@ -827,7 +1102,12 @@ public final class CMSettings {
|
||||
* or not a valid integer.
|
||||
*/
|
||||
public static int getInt(ContentResolver cr, String name, int def) {
|
||||
String v = getString(cr, name);
|
||||
return getIntForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static int getIntForUser(ContentResolver cr, String name, int def, int userId) {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return v != null ? Integer.parseInt(v) : def;
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -836,7 +1116,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as an integer. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to an integer
|
||||
* for you.
|
||||
@@ -855,7 +1135,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static int getInt(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getString(cr, name);
|
||||
return getIntForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static int getIntForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return Integer.parseInt(v);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -877,11 +1163,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putInt(ContentResolver cr, String name, int value) {
|
||||
return putString(cr, name, Integer.toString(value));
|
||||
return putIntForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putIntForUser(ContentResolver cr, String name, int value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Integer.toString(value), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a {@code long}. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a {@code long}
|
||||
* for you. The default value will be returned if the setting is
|
||||
@@ -895,7 +1187,13 @@ public final class CMSettings {
|
||||
* or not a valid {@code long}.
|
||||
*/
|
||||
public static long getLong(ContentResolver cr, String name, long def) {
|
||||
String valString = getString(cr, name);
|
||||
return getLongForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static long getLongForUser(ContentResolver cr, String name, long def,
|
||||
int userId) {
|
||||
String valString = getStringForUser(cr, name, userId);
|
||||
long value;
|
||||
try {
|
||||
value = valString != null ? Long.parseLong(valString) : def;
|
||||
@@ -906,7 +1204,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a {@code long}. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a {@code long}
|
||||
* for you.
|
||||
@@ -924,7 +1222,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static long getLong(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String valString = getString(cr, name);
|
||||
return getLongForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static long getLongForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String valString = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return Long.parseLong(valString);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -933,7 +1237,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for updating a secure settings value as a long
|
||||
* Convenience function for updating a single settings value as a long
|
||||
* integer. This will either create a new entry in the table if the
|
||||
* given name does not exist, or modify the value of the existing row
|
||||
* with that name. Note that internally setting values are always
|
||||
@@ -946,11 +1250,17 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putLong(ContentResolver cr, String name, long value) {
|
||||
return putString(cr, name, Long.toString(value));
|
||||
return putLongForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putLongForUser(ContentResolver cr, String name, long value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Long.toString(value), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single settings value
|
||||
* as a floating point number. Note that internally setting values are
|
||||
* always stored as strings; this function converts the string to an
|
||||
* float for you. The default value will be returned if the setting
|
||||
@@ -964,7 +1274,13 @@ public final class CMSettings {
|
||||
* or not a valid float.
|
||||
*/
|
||||
public static float getFloat(ContentResolver cr, String name, float def) {
|
||||
String v = getString(cr, name);
|
||||
return getFloatForUser(cr, name, def, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static float getFloatForUser(ContentResolver cr, String name, float def,
|
||||
int userId) {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
try {
|
||||
return v != null ? Float.parseFloat(v) : def;
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -973,7 +1289,7 @@ public final class CMSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for retrieving a single secure settings value
|
||||
* Convenience function for retrieving a single system settings value
|
||||
* as a float. Note that internally setting values are always
|
||||
* stored as strings; this function converts the string to a float
|
||||
* for you.
|
||||
@@ -992,7 +1308,13 @@ public final class CMSettings {
|
||||
*/
|
||||
public static float getFloat(ContentResolver cr, String name)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getString(cr, name);
|
||||
return getFloatForUser(cr, name, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static float getFloatForUser(ContentResolver cr, String name, int userId)
|
||||
throws CMSettingNotFoundException {
|
||||
String v = getStringForUser(cr, name, userId);
|
||||
if (v == null) {
|
||||
throw new CMSettingNotFoundException(name);
|
||||
}
|
||||
@@ -1017,7 +1339,13 @@ public final class CMSettings {
|
||||
* @return true if the value was set, false on database errors
|
||||
*/
|
||||
public static boolean putFloat(ContentResolver cr, String name, float value) {
|
||||
return putString(cr, name, Float.toString(value));
|
||||
return putFloatForUser(cr, name, value, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static boolean putFloatForUser(ContentResolver cr, String name, float value,
|
||||
int userId) {
|
||||
return putStringForUser(cr, name, Float.toString(value), userId);
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -1032,7 +1360,7 @@ public final class CMSettings {
|
||||
public static final String DEVICE_NAME = "device_name";
|
||||
|
||||
/**
|
||||
* Defines global heads up toggle. One of HEADS_UP_OFF, HEADS_UP_ON.
|
||||
* Defines global heads up toggle. One of HEADS_UP_OFF, HEADS_UP_ON.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user