diff options
author | Mike Lockwood <> | 2009-04-02 21:41:57 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-02 21:41:57 -0700 |
commit | 9637d474899d9725da8a41fdf92b9bd1a15d301e (patch) | |
tree | 5383ecf1ab4bd1e34df329c276309b29dc8ef225 /core | |
parent | f80f5d02ed5793d1a9bf6f69885fa3c509e7d312 (diff) | |
download | frameworks_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 'core')
-rw-r--r-- | core/java/android/provider/Settings.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 993e4dc..d7d7c2e 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2113,6 +2113,46 @@ public final class Settings { * @hide */ public static final String TTY_MODE_ENABLED = "tty_mode_enabled"; + + /** + * Helper method for determining if a location provider is enabled. + * @param cr the content resolver to use + * @param provider the location provider to query + * @return true if the provider is enabled + * + * @hide + */ + public static final boolean isLocationProviderEnabled(ContentResolver cr, String provider) { + String allowedProviders = Settings.Secure.getString(cr, LOCATION_PROVIDERS_ALLOWED); + if (allowedProviders != null) { + return (allowedProviders.equals(provider) || + allowedProviders.contains("," + provider + ",") || + allowedProviders.startsWith(provider + ",") || + allowedProviders.endsWith("," + provider)); + } + return false; + } + + /** + * Thread-safe method for enabling or disabling a single location provider. + * @param cr the content resolver to use + * @param provider the location provider to enable or disable + * @param enabled true if the provider should be enabled + * + * @hide + */ + public static final void setLocationProviderEnabled(ContentResolver cr, + String provider, boolean enabled) { + // to ensure thread safety, we write the provider name with a '+' or '-' + // and let the SettingsProvider handle it rather than reading and modifying + // the list of enabled providers. + if (enabled) { + provider = "+" + provider; + } else { + provider = "-" + provider; + } + putString(cr, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, provider); + } } /** |