summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorMike Lockwood <>2009-04-02 21:41:57 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-02 21:41:57 -0700
commit9637d474899d9725da8a41fdf92b9bd1a15d301e (patch)
tree5383ecf1ab4bd1e34df329c276309b29dc8ef225 /packages
parentf80f5d02ed5793d1a9bf6f69885fa3c509e7d312 (diff)
downloadframeworks_base-9637d474899d9725da8a41fdf92b9bd1a15d301e.zip
frameworks_base-9637d474899d9725da8a41fdf92b9bd1a15d301e.tar.gz
frameworks_base-9637d474899d9725da8a41fdf92b9bd1a15d301e.tar.bz2
AI 144372: Cleanup Settings support for enabling and disabling location providers:
LocationManagerService now listens for changes to settings, making LocationManager.updateProviders() unnecessary. Removed LocationManager.updateProviders() Added Settings.Secure.setLocationProviderEnabled(), which is a thread-safe way of enabling or disabling a single location provider. This is safer than reading, modifying and writing the LOCATION_PROVIDERS_ALLOWED directly. BUG=1729031 Automated import of CL 144372
Diffstat (limited to 'packages')
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 333a450..6f430c4 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -244,6 +244,72 @@ public class SettingsProvider extends ContentProvider {
return values.length;
}
+ /*
+ * 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.
+ */
+ private boolean parseProviderList(Uri url, ContentValues initialValues) {
+ String value = initialValues.getAsString(Settings.Secure.VALUE);
+ String newProviders = null;
+ if (value != null && value.length() > 1) {
+ char prefix = value.charAt(0);
+ if (prefix == '+' || prefix == '-') {
+ // skip prefix
+ value = value.substring(1);
+
+ // read list of enabled providers into "providers"
+ String providers = "";
+ String[] columns = {Settings.Secure.VALUE};
+ String where = Settings.Secure.NAME + "=\'" + Settings.Secure.LOCATION_PROVIDERS_ALLOWED + "\'";
+ Cursor cursor = query(url, columns, where, null, null);
+ if (cursor != null && cursor.getCount() == 1) {
+ try {
+ cursor.moveToFirst();
+ providers = cursor.getString(0);
+ } finally {
+ cursor.close();
+ }
+ }
+
+ int index = providers.indexOf(value);
+ int end = index + value.length();
+ // check for commas to avoid matching on partial string
+ if (index > 0 && providers.charAt(index - 1) != ',') index = -1;
+ if (end < providers.length() && providers.charAt(end) != ',') index = -1;
+
+ if (prefix == '+' && index < 0) {
+ // append the provider to the list if not present
+ if (providers.length() == 0) {
+ newProviders = value;
+ } else {
+ newProviders = providers + ',' + value;
+ }
+ } else if (prefix == '-' && index >= 0) {
+ // remove the provider from the list if present
+ // remove leading and trailing commas
+ if (index > 0) index--;
+ if (end < providers.length()) end++;
+
+ newProviders = providers.substring(0, index);
+ if (end < providers.length()) {
+ newProviders += providers.substring(end);
+ }
+ } else {
+ // nothing changed, so no need to update the database
+ return false;
+ }
+
+ if (newProviders != null) {
+ initialValues.put(Settings.Secure.VALUE, newProviders);
+ }
+ }
+ }
+
+ return true;
+ }
+
@Override
public Uri insert(Uri url, ContentValues initialValues) {
SqlArguments args = new SqlArguments(url);
@@ -252,6 +318,13 @@ public class SettingsProvider extends ContentProvider {
}
checkWritePermissions(args);
+ // Special case LOCATION_PROVIDERS_ALLOWED.
+ // Support enabling/disabling a single provider (using "+" or "-" prefix)
+ String name = initialValues.getAsString(Settings.Secure.NAME);
+ if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) {
+ if (!parseProviderList(url, initialValues)) return null;
+ }
+
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
final long rowId = db.insert(args.table, null, initialValues);
if (rowId <= 0) return null;