CoreSettingsObserverpublic final class CoreSettingsObserver extends android.database.ContentObserver Helper class for watching a set of core settings which the framework
propagates to application processes to avoid multiple lookups and potentially
disk I/O operations. Note: This class assumes that all core settings reside
in {@link Settings.Secure}. |
Fields Summary |
---|
private static final String | LOG_TAG | private static final Map | sSecureSettingToTypeMap | private static final Map | sSystemSettingToTypeMap | private static final Map | sGlobalSettingToTypeMap | private final android.os.Bundle | mCoreSettings | private final ActivityManagerService | mActivityManagerService |
Constructors Summary |
---|
public CoreSettingsObserver(ActivityManagerService activityManagerService)
super(activityManagerService.mHandler);
mActivityManagerService = activityManagerService;
beginObserveCoreSettings();
sendCoreSettings();
|
Methods Summary |
---|
private void | beginObserveCoreSettings()
for (String setting : sSecureSettingToTypeMap.keySet()) {
Uri uri = Settings.Secure.getUriFor(setting);
mActivityManagerService.mContext.getContentResolver().registerContentObserver(
uri, false, this);
}
for (String setting : sSystemSettingToTypeMap.keySet()) {
Uri uri = Settings.System.getUriFor(setting);
mActivityManagerService.mContext.getContentResolver().registerContentObserver(
uri, false, this);
}
for (String setting : sGlobalSettingToTypeMap.keySet()) {
Uri uri = Settings.Global.getUriFor(setting);
mActivityManagerService.mContext.getContentResolver().registerContentObserver(
uri, false, this);
}
| public android.os.Bundle | getCoreSettingsLocked()
return (Bundle) mCoreSettings.clone();
| public void | onChange(boolean selfChange)
synchronized (mActivityManagerService) {
sendCoreSettings();
}
| private void | populateSettings(android.os.Bundle snapshot, java.util.Map map)
Context context = mActivityManagerService.mContext;
for (Map.Entry<String, Class<?>> entry : map.entrySet()) {
String setting = entry.getKey();
Class<?> type = entry.getValue();
if (type == String.class) {
final String value;
if (map == sSecureSettingToTypeMap) {
value = Settings.Secure.getString(context.getContentResolver(), setting);
} else if (map == sSystemSettingToTypeMap) {
value = Settings.System.getString(context.getContentResolver(), setting);
} else {
value = Settings.Global.getString(context.getContentResolver(), setting);
}
snapshot.putString(setting, value);
} else if (type == int.class) {
final int value;
if (map == sSecureSettingToTypeMap) {
value = Settings.Secure.getInt(context.getContentResolver(), setting, 0);
} else if (map == sSystemSettingToTypeMap) {
value = Settings.System.getInt(context.getContentResolver(), setting, 0);
} else {
value = Settings.Global.getInt(context.getContentResolver(), setting, 0);
}
snapshot.putInt(setting, value);
} else if (type == float.class) {
final float value;
if (map == sSecureSettingToTypeMap) {
value = Settings.Secure.getFloat(context.getContentResolver(), setting, 0);
} else if (map == sSystemSettingToTypeMap) {
value = Settings.System.getFloat(context.getContentResolver(), setting, 0);
} else {
value = Settings.Global.getFloat(context.getContentResolver(), setting, 0);
}
snapshot.putFloat(setting, value);
} else if (type == long.class) {
final long value;
if (map == sSecureSettingToTypeMap) {
value = Settings.Secure.getLong(context.getContentResolver(), setting, 0);
} else if (map == sSystemSettingToTypeMap) {
value = Settings.System.getLong(context.getContentResolver(), setting, 0);
} else {
value = Settings.Global.getLong(context.getContentResolver(), setting, 0);
}
snapshot.putLong(setting, value);
}
}
| private void | sendCoreSettings()
populateSettings(mCoreSettings, sSecureSettingToTypeMap);
populateSettings(mCoreSettings, sSystemSettingToTypeMap);
populateSettings(mCoreSettings, sGlobalSettingToTypeMap);
mActivityManagerService.onCoreSettingsChange(mCoreSettings);
|
|