From 5ed2c4ad43f2c3c85a025da04becd2eaa75927a1 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Sun, 7 Jun 2009 23:07:20 -0400 Subject: [PATCH] Listen for changes to location pProvider enabled settings. This is needed so we can correctly update the network location checkbox if the network location provider is disabled because the user disagreed to the terms of service in a dialog shown by the provider. Signed-off-by: Mike Lockwood --- .../android/settings/SecuritySettings.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index c6b19ce5287..166fa446960 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -18,9 +18,11 @@ package com.android.settings; import android.app.Activity; +import android.content.ContentQueryMap; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.database.Cursor; import android.location.LocationManager; import android.os.Bundle; import android.preference.CheckBoxPreference; @@ -32,6 +34,9 @@ import android.provider.Settings; import android.util.Config; import android.util.Log; +import java.util.Observable; +import java.util.Observer; + import com.android.internal.widget.LockPatternUtils; /** @@ -62,6 +67,16 @@ public class SecuritySettings extends PreferenceActivity { private CheckBoxPreference mNetwork; private CheckBoxPreference mGps; + // These provide support for receiving notification when Location Manager settings change. + // This is necessary because the Network Location Provider can change settings + // if the user does not confirm enabling the provider. + private ContentQueryMap mContentQueryMap; + private final class SettingsObserver implements Observer { + public void update(Observable o, Object arg) { + updateToggles(); + } + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -74,6 +89,14 @@ public class SecuritySettings extends PreferenceActivity { mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK); mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS); updateToggles(); + + // listen for Location Manager settings changes + Cursor settingsCursor = getContentResolver().query(Settings.Secure.CONTENT_URI, null, + "(" + Settings.System.NAME + "=?)", + new String[]{Settings.Secure.LOCATION_PROVIDERS_ALLOWED}, + null); + mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null); + mContentQueryMap.addObserver(new SettingsObserver()); } private PreferenceScreen createPreferenceHierarchy() {