use of com.android.providers.settings.SettingsState.Setting in project platform_frameworks_base by android.
the class SettingsProvider method getAllSystemSettings.
private Cursor getAllSystemSettings(int userId, String[] projection) {
if (DEBUG) {
Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")");
}
// Resolve the userId on whose behalf the call is made.
final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);
synchronized (mLock) {
List<String> names = mSettingsRegistry.getSettingsNamesLocked(SETTINGS_TYPE_SYSTEM, callingUserId);
final int nameCount = names.size();
String[] normalizedProjection = normalizeProjection(projection);
MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
for (int i = 0; i < nameCount; i++) {
String name = names.get(i);
// Determine the owning user as some profile settings are cloned from the parent.
final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name);
Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SYSTEM, owningUserId, name);
appendSettingToCursor(result, setting);
}
return result;
}
}
use of com.android.providers.settings.SettingsState.Setting in project platform_frameworks_base by android.
the class SettingsProvider method updateLocationProvidersAllowedLocked.
/*
* Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED.
* This setting contains a list of the currently enabled location providers.
* But helper functions in android.providers.Settings can enable or disable
* a single provider by using a "+" or "-" prefix before the provider name.
*
* <p>See also {@link #isGlobalOrSecureSettingRestrictedForUser()}. If DISALLOW_SHARE_LOCATION
* is set, the said method will only allow values with the "-" prefix.
*
* @returns whether the enabled location providers changed.
*/
private boolean updateLocationProvidersAllowedLocked(String value, int owningUserId, boolean forceNotify) {
if (TextUtils.isEmpty(value)) {
return false;
}
final char prefix = value.charAt(0);
if (prefix != '+' && prefix != '-') {
if (forceNotify) {
final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId);
mSettingsRegistry.notifyForSettingsChange(key, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
}
return false;
}
// skip prefix
value = value.substring(1);
Setting settingValue = getSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, owningUserId);
String oldProviders = (settingValue != null) ? settingValue.getValue() : "";
int index = oldProviders.indexOf(value);
int end = index + value.length();
// check for commas to avoid matching on partial string
if (index > 0 && oldProviders.charAt(index - 1) != ',') {
index = -1;
}
// check for commas to avoid matching on partial string
if (end < oldProviders.length() && oldProviders.charAt(end) != ',') {
index = -1;
}
String newProviders;
if (prefix == '+' && index < 0) {
// append the provider to the list if not present
if (oldProviders.length() == 0) {
newProviders = value;
} else {
newProviders = oldProviders + ',' + value;
}
} else if (prefix == '-' && index >= 0) {
// remove leading or trailing comma
if (index > 0) {
index--;
} else if (end < oldProviders.length()) {
end++;
}
newProviders = oldProviders.substring(0, index);
if (end < oldProviders.length()) {
newProviders += oldProviders.substring(end);
}
} else {
// nothing changed, so no need to update the database
if (forceNotify) {
final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId);
mSettingsRegistry.notifyForSettingsChange(key, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
}
return false;
}
return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, newProviders, getCallingPackage(), forceNotify);
}
use of com.android.providers.settings.SettingsState.Setting in project android_frameworks_base by crdroidandroid.
the class SettingsProvider method updateLocationProvidersAllowedLocked.
/*
* Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED.
* This setting contains a list of the currently enabled location providers.
* But helper functions in android.providers.Settings can enable or disable
* a single provider by using a "+" or "-" prefix before the provider name.
*
* <p>See also {@link #isGlobalOrSecureSettingRestrictedForUser()}. If DISALLOW_SHARE_LOCATION
* is set, the said method will only allow values with the "-" prefix.
*
* @returns whether the enabled location providers changed.
*/
private boolean updateLocationProvidersAllowedLocked(String value, int owningUserId, boolean forceNotify) {
if (TextUtils.isEmpty(value)) {
return false;
}
final char prefix = value.charAt(0);
if (prefix != '+' && prefix != '-') {
if (forceNotify) {
final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId);
mSettingsRegistry.notifyForSettingsChange(key, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
}
return false;
}
// skip prefix
value = value.substring(1);
Setting settingValue = getSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, owningUserId);
String oldProviders = (settingValue != null) ? settingValue.getValue() : "";
int index = oldProviders.indexOf(value);
int end = index + value.length();
// check for commas to avoid matching on partial string
if (index > 0 && oldProviders.charAt(index - 1) != ',') {
index = -1;
}
// check for commas to avoid matching on partial string
if (end < oldProviders.length() && oldProviders.charAt(end) != ',') {
index = -1;
}
String newProviders;
if (prefix == '+' && index < 0) {
// append the provider to the list if not present
if (oldProviders.length() == 0) {
newProviders = value;
} else {
newProviders = oldProviders + ',' + value;
}
} else if (prefix == '-' && index >= 0) {
// remove leading or trailing comma
if (index > 0) {
index--;
} else if (end < oldProviders.length()) {
end++;
}
newProviders = oldProviders.substring(0, index);
if (end < oldProviders.length()) {
newProviders += oldProviders.substring(end);
}
} else {
// nothing changed, so no need to update the database
if (forceNotify) {
final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId);
mSettingsRegistry.notifyForSettingsChange(key, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
}
return false;
}
return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, newProviders, getCallingPackage(), forceNotify);
}
use of com.android.providers.settings.SettingsState.Setting in project android_frameworks_base by crdroidandroid.
the class SettingsProvider method getAllGlobalSettings.
private Cursor getAllGlobalSettings(String[] projection) {
if (DEBUG) {
Slog.v(LOG_TAG, "getAllGlobalSettings()");
}
synchronized (mLock) {
// Get the settings.
SettingsState settingsState = mSettingsRegistry.getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
List<String> names = settingsState.getSettingNamesLocked();
final int nameCount = names.size();
String[] normalizedProjection = normalizeProjection(projection);
MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
// Anyone can get the global settings, so no security checks.
for (int i = 0; i < nameCount; i++) {
String name = names.get(i);
Setting setting = settingsState.getSettingLocked(name);
appendSettingToCursor(result, setting);
}
return result;
}
}
use of com.android.providers.settings.SettingsState.Setting in project platform_frameworks_base by android.
the class SettingsProvider method getAllSecureSettings.
private Cursor getAllSecureSettings(int userId, String[] projection) {
if (DEBUG) {
Slog.v(LOG_TAG, "getAllSecureSettings(" + userId + ")");
}
// Resolve the userId on whose behalf the call is made.
final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);
synchronized (mLock) {
List<String> names = mSettingsRegistry.getSettingsNamesLocked(SETTINGS_TYPE_SECURE, callingUserId);
final int nameCount = names.size();
String[] normalizedProjection = normalizeProjection(projection);
MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
for (int i = 0; i < nameCount; i++) {
String name = names.get(i);
// Determine the owning user as some profile settings are cloned from the parent.
final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name);
// Special case for location (sigh).
if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) {
continue;
}
Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, name);
appendSettingToCursor(result, setting);
}
return result;
}
}
Aggregations